﻿using System;

namespace AOP.Util
{
    public static class Log
    {
        private static readonly AssumeLog elapseLog = new AssumeLog();
        private static readonly AssumeLog timeoutLog = new AssumeLog();
        private const string timeoutLogMsgTemplates = "AOP拦截方法超时,耗时:{0},执行方法:{1}";

        public static void Record(string msg, long elapsedMilliseconds)
        {
            elapseLog.Warn(string.Format("{0}`{1}", msg, elapsedMilliseconds));
            //AOP拦截请求超时日志记录
            if (elapsedMilliseconds > 2000)
            {
                timeoutLog.Fatal(string.Format(timeoutLogMsgTemplates, elapsedMilliseconds, msg));
            }
            else if (elapsedMilliseconds > 1000)
            {
                timeoutLog.Error(string.Format(timeoutLogMsgTemplates, elapsedMilliseconds, msg));
            }
            else if (elapsedMilliseconds > 500)
            {
                timeoutLog.Warn(string.Format(timeoutLogMsgTemplates, elapsedMilliseconds, msg));
            }
        }
    }
}
